#include <cstring>
#include <iostream>
using namespace std;
//---------------基类--------------

class Mobile
{
private:
  char mynumber[11];

public:
  void init(char number[11]);
  void dial(char *);
  void answer(char othernumber[11]);
  void hangup() { cout << "hanging ip..." << endl; }
  void show() { cout << "my number is " << mynumber << endl; }
};

//设置本机号码，默认00000000
void Mobile::init(char number[11] = "0000000000")
{
  strcpy(mynumber, number);
}

void Mobile::dial(char *number)
{
  cout << "dialing number is " << number << endl;
  cout << "dialing on..." << endl;
}

void Mobile::answer(char othernumber[11])
{
  cout << "answering number is " << othernumber << endl;
  cout << "answering in..." << endl;
}

//--------定义智能手机类，继承基类
class SmartPhone : public Mobile
{
private:
  char OS[20];
  int memory;
public:
  void init(char number[11], char *os, int mem); //派生类初始化
  void send(char othernumber[11], char message[150]);//发送短信
  void showmemory();//显示内存
  void show();//显示信息
};

//-------派生类函数定义
void SmartPhone::init(char num[11],char *os, int mem) //覆盖init函数
{
  Mobile::init(num); //调用基类成员函数
  strcpy(OS, os);
  memory = mem;
}

//发送短信
void SmartPhone::send(char othernumber[11], char message[150])
{
  cout << "sending message" << message << "to" << othernumber << endl;
  cout << "sending on" << endl;
}

void SmartPhone::showmemory()
{
  cout << "memory is:" << memory << "MB" << endl;
}

void SmartPhone::show()
{
  cout << "os is " << OS << endl;
  cout << "Memory is:" << memory << "MB" << endl;
  Mobile::show();
}

//-------主程序
int main()
{
  Mobile ctec;
  SmartPhone csat;

  cout << "------Mobile Phone ctec--------\n";
  ctec.init("13772646322");
  ctec.dial("13320203320");
  ctec.answer("1333213213");
  ctec.hangup();

  //派生类对象
  cout << endl;
  cout << "--------smart phone csat----\n";
  csat.init("13772646322");
  csat.dial("13320203320");
  csat.answer("1333213213");
  csat.hangup();
  csat.Mobile::show();//访问基类的同名函数一定要显式访问
  csat.Mobile::init("123123213");
  csat.answer("213123213");
  csat.hangup();
  csat.show();

  return 0;
}
